<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>用户登陆</title>
</head>
<body>
	<fieldset id="">
		<legend style="font-size: 25px; color: black">项目信息维护</legend>
		<div class="layui-form">
			<div class="layui-field-box">
				<!-- <form class="layui-form" > -->
				<div class="layui-form-item">
					<label class="layui-form-label">项目代码</label>
					<div class="layui-input-inline">
						<input type="text" name="code" placeholder="请输入项目代码"
							autocomplete="off" class="layui-input">
					</div>
					<label class="layui-form-label">项目名称</label>
					<div class="layui-input-inline">
						<input type="text" name="name" placeholder="请输入项目名称"
							autocomplete="off" class="layui-input">
					</div>

					<input type="button" id="selc" value="搜索" lay-submit
						lay-filter="search" class="layui-btn" /> <input
						onclick="openAdd()" type="button" value="添加" class="layui-btn"
						id="add1" />
				</div>

			</div>
			<input type="hidden" name="action" value="page"> <input
				type="hidden" name="pageIndex" value="1"> <input
				type="hidden" name="pageLimit" value="10">

		</div>
		<table style="" class=" layui-table">
			<thead>
				<tr>
					<th style="width: 15%; text-align: left;">ID</th>
					<th style="width: 15%; text-align: left;">项目编号</th>
					<th style="width: 15%; text-align: left;">项目名称</th>
					<th style="width: 15%; text-align: left;">项目开始时间</th>
					<th style="width: 15%; text-align: left;">操作</th>
				</tr>
			</thead>
			<tbody id="tbody">

			</tbody>
		</table>
		<div id="pageInfoPro" style="text-align: right; padding-right: 30px"></div>
	</fieldset>
	<script type="text/javascript">
		formSubmit("/ProjectServlet","submit(search)","json",function(data){
			var cur = $("input[name='pageIndex']").val();
			var limit = $("input[name='pageLimit']").val();
			
			setPageInfo("pageInfoPro",data.count,cur,limit,function(obj,first){
// 				console.log(obj)
				$("input[name='pageIndex']").val(obj.curr);
				$("input[name='pageLimit']").val(obj.limit);
				if(!first){
					refresh();
				}
			});
			
			var html="";
			$.each(data.list,function(i,every){
				var proCode = every.code?every.code:'';
				var proName = every.name?every.name:'';
				var proTime = every.time?every.time:'';
				var d ={i:i+1,code:proCode,name:proName,time:proTime};
// 				console.log(d)
				html += getlaytpl("#tradd3",d)
			})
			$("#tbody").html(html);
			layer.msg("查询成功")
		})
		refresh();
		function refresh(){
			$("input[value='搜索']").click();
		}
		
		function openAdd(){
			openlayerPro("/web/page/pro/add.jsp",refresh);
		}
		
		function del(code){
			openConfirm(function(){
				ajax("/ProjectServlet",{action:"del",code:code},"text",function(data){
					if(1==data){
						layer.msg("删除成功",refresh);
					}
				})
			})
		}
		function openUpd(code){
			openlayer("/web/page/pro/upd.jsp?code="+code,refresh);
		}
		
		
	</script>

	<script type="text/html" id = "tradd3">
			<tr >
				<td>{{d.i}}</td>
				<td>{{d.code}}</td>
				<td>{{d.name}}</td>
				<td>{{d.time}}</td>
				<td>
					<a href='javascript:del("{{d.code}}")' 
					class = "layui-btn layui-btn-sm layui-btn-danger">
					<i class="layui-icon layui-icon-delete">
					</a>&nbsp;&nbsp;
					<input type="button" onclick='openUpd("{{d.code}}")'
						class="layui-btn layui-btn-sm" value="修改" />
				</td>
			</tr>
		</script>

</body>
</html>
